<?php

namespace app\library;

/**
 * IP 处理
 * @package common\library\utils
 */
class IP
{
    /**
     * 获取用户IP
     * @return string IP String
     */
    public static function UserIp() {
        $realIp = '';
        if (isset ( $_SERVER )) {
            if (isset ( $_SERVER ['HTTP_X_FORWARDED_FOR'] )) {
                $realIp = $_SERVER ['HTTP_X_FORWARDED_FOR'];
            } elseif (isset ( $_SERVER ['HTTP_CLIENT_IP'] )) {
                $realIp = $_SERVER ['HTTP_CLIENT_IP'];
            } else {
                $realIp = $_SERVER ['REMOTE_ADDR'];
            }
        } else {
            if (getenv ( 'HTTP_X_FORWARDED_FOR' )) {
                $realIp = getenv ( 'HTTP_X_FORWARDED_FOR' );
            } elseif (getenv ( 'HTTP_CLIENT_IP' )) {
                $realIp = getenv ( 'HTTP_CLIENT_IP' );
            } else {
                $realIp = getenv ( 'REMOTE_ADDR' );
            }
        }
        return $realIp;
    }
}